package com.efast.dmom.mes.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.cafe.commponent.code.bean.GenerateCodeBean;
import com.efast.cafe.commponent.code.bean.ReturnGenerateCodeBean;
import com.efast.cafe.commponent.code.service.CodeInstanceService;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mes.entity.base.WmsBaseEntity;
@Component
public class ServiceBaseEntityUtil {
	@Autowired
	private  CodeInstanceService codeInstanceService;
	
	public static void setSaveBaseEntityData (WmsBaseEntity entity) {
		entity.setCreateTime(TimeUtil.getLocalDateTime());
		entity.setCreateUser(SpringWebUtils.getRequestUser());
		entity.setCompanyCode(SpringWebUtils.getRequestCompany());
		entity.setLastUpdateTime(TimeUtil.getLocalDateTime());
		entity.setLastUpdateUser(SpringWebUtils.getRequestUser());
	}
	
	public static void setUpdateBaseEntityData (WmsBaseEntity entity) {
		entity.setLastUpdateTime(TimeUtil.getLocalDateTime());
		entity.setLastUpdateUser(SpringWebUtils.getRequestUser());
	}
	
	public static void setUpdateLogEntityData (WmsBaseEntity entity) {
		entity.setCreateTime(TimeUtil.getLocalDateTime());
		entity.setCreateUser(SpringWebUtils.getRequestUser());
		entity.setCompanyCode(SpringWebUtils.getRequestCompany());
	}
	
	public  String getNo(String code) {
		GenerateCodeBean bean = new GenerateCodeBean();
		bean.setCompanyCode(SpringWebUtils.getRequestCompany());
		bean.setCreateUser(SpringWebUtils.getRequestUser());
		bean.setInstanceId(code);
		ReturnGenerateCodeBean codeBean = codeInstanceService.generateCode(bean);
		return codeBean.getCode();
		
	}

}
